﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WayneGameSolution.Chat
{
   public  class PrivateChatChannel:ChatChannelBase
    {
        public PrivateChatChannel ():base()
        {}

        public PrivateChatChannel(string id, string name, int timeoutSecond, ChannelType type) 
            :base (id,name,timeoutSecond ,type )
        {}

        public override IEnumerable<IChatMessage> GetUserMessage(string user)
        {


            DateTime lt;

            LastReceivedTime.TryGetValue(user, out lt);
            if (lt == null) lt = DateTime.MinValue;

            var ls = SearchMessagesFromLast (lt)
                .Reverse()
                .Where(chm => chm.ChaterTo == user || chm.ChaterFrom == user)
                .ToList();
            LastReceivedTime[user] =ls[ ls.Count -1].TimeStamp  ;
            return ls;
     
        }
    }
}
